ALTER PROCEDURE sp_create_update_Fab_Invoice_Cost
(
	@PART_NUMBER  VARCHAR(50),
	@LOT_NUMBER	  VARCHAR(50), 	
	@INVOICE_COST NUMERIC(18,4),
	@VENDOR		  VARCHAR(50)
)
AS
BEGIN
	DECLARE @LOT_ID INT
 	DECLARE @PROCESS_STEP_ID INT
 	DECLARE @LOCATION_ID INT
	
 	SELECT @LOCATION_ID = LOCATION_ID FROM LOCATION WHERE L_TYPE = 'FAB' AND L_VENDOR_NAME = @VENDOR
	SELECT @PROCESS_STEP_ID = PROCESS_STEP_ID FROM FN_GET_PROCESS_STEP_ID(@PART_NUMBER,'FAB','FAB' )
	IF @PROCESS_STEP_ID IS NULL OR @LOCATION_ID IS NULL 
	BEGIN
		 -- DUMMY UPDATE TO AVOID SQLEXCEPTION
		UPDATE CLIENT_TABLE SET [NAME] = 'LOT_NUMBER' WHERE [NAME] = 'LOT_NUMBER'
		RETURN
	END

	SELECT @LOT_ID = LOT_ID FROM LOT_TABLE WHERE PROCESSSTEP_ID = @PROCESS_STEP_ID AND LOCATION_ID = @LOCATION_ID AND LOT_NUMBER = @LOT_NUMBER
	IF @LOT_ID IS NOT NULL
	BEGIn
		UPDATE LOT_TABLE SET INVOICE_COST = @INVOICE_COST WHERE LOT_ID = @LOT_ID
	END
END